package com.zbkj.admin.controller.platform.assistant;

import com.zbkj.admin.controller.platform.assistant.service.AssistantMessageService;
import com.zbkj.common.model.admin.SystemAdmin;
import com.zbkj.common.page.CommonPage;
import com.zbkj.common.request.PageParamRequest;
import com.zbkj.common.utils.SecurityUtil;
import com.zbkj.service.assistant.model.request.AssistantMessageAdminSearchRequest;
import com.zbkj.service.assistant.model.request.AssistantMessageAdminSendRequest;
import com.zbkj.common.result.CommonResult;
import com.zbkj.service.assistant.model.request.AssistantMessageReadRequest;
import com.zbkj.service.assistant.model.vo.AssistantMessageVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * 消息表 前端控制器
 */
@Slf4j
@RestController
@RequestMapping("api/admin/platform/assistant/message")
@Api(tags = "客服-消息") //配合swagger使用

public class AssistantMessageController {

    @Autowired
    private AssistantMessageService assistantMessageService;

    @ApiOperation(value = "指定会话的消息列表")
    @GetMapping("/list/conversation")
    public CommonResult<List<AssistantMessageVO>> getList(@RequestParam Integer conversationId) {
        return CommonResult.success(assistantMessageService.findByConversationId(conversationId));
    }

    @ApiOperation(value = "分页列表") //配合swagger使用
    @GetMapping("/list")
    public CommonResult<CommonPage<AssistantMessageVO>>  getList(@Validated AssistantMessageAdminSearchRequest request, @Validated PageParamRequest pageParamRequest) {
        CommonPage<AssistantMessageVO> assistantMessageCommonPage = CommonPage.restPage(assistantMessageService.getAdminMessageList(request, pageParamRequest));
        return CommonResult.success(assistantMessageCommonPage);
    }

    @ApiOperation(value = "发送消息给用户")
    @PostMapping("/send")
    public CommonResult<AssistantMessageVO> save(@RequestBody @Validated AssistantMessageAdminSendRequest request) {
        SystemAdmin admin = SecurityUtil.getLoginUserVo().getUser();
        AssistantMessageVO assistantMessage = assistantMessageService.sendByAdmin(request, admin.getId());
        return CommonResult.success(assistantMessage);
    }

    @ApiOperation(value = "读消息")
    @PostMapping("/read")
    public CommonResult<Void> read(@RequestBody @Validated AssistantMessageReadRequest request) {
        assistantMessageService.read(request.getMessageId());
        return CommonResult.success();
    }

}



